package cn.yotta.user.web.autoconfiguration.utils;

import lombok.experimental.UtilityClass;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wyaoyao
 * @date 2022/11/8 14:53
 */
@UtilityClass
public class HeaderUtils {

    public Map<String, String> readHeaders(HttpServletRequest request) {
        final Enumeration<String> headerNames = request.getHeaderNames();
        Map<String, String> headers = new HashMap<>(16);
        while (headerNames.hasMoreElements()) {
            final String headerName = headerNames.nextElement();
            headers.put(headerName, request.getHeader(headerName));
        }
        return headers;
    }
}
